package com.stormrage.edu.dao.learn.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.stormrage.edu.dao.learn.LeaStudentCourseDao;
import com.stormrage.entity.learn.rep.LeaStudentCourseRep;
import com.stormragetech.core.dao.MysBaseDao;
import com.stormragetech.core.exception.StormrageTechException;

/**
 * @Title: LeaStudentCourseDaoImpl.java
 * @Package com.stormrage.edu.dao.learn.impl
 * @Description: 课程学习进度 Dao
 * @author www.stormragetech.com
 * @date 2016年4月29日
 * @version V1.0
 */
@Repository
public class LeaStudentCourseDaoImpl extends MysBaseDao implements LeaStudentCourseDao {

	private static final Logger logger = LoggerFactory.getLogger(LeaBunchUsuaDaoImpl.class);

	@Override
	public Integer queryRepCountByStuId(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 LeaStudentCourseDao 】-【 queryRepCountByStuId 】- 开始运行 ");

		final String query = "SELECT COUNT(e.id) FROM lea_student AS a, lea_bunch AS b, lea_term AS c,"
				+ " edu_major_module AS d, edu_module_course AS e, edu_module AS f WHERE a.id = :stuId"
				+ " AND a.bunch_id = b.id AND b.term_id = c.id AND c.major_id = d.major_id AND d.module_id = e.module_id"
				+ " AND d.module_id = f.id AND f.ness = 0";
		logger.debug(" 数据库执行语句为 " + query);

		Integer count = queryCount(query, map);

		logger.debug(" 【 Dao 】-【 LeaStudentCourseDao 】-【 queryRepCountByStuId 】- 完成运行 ");
		return count;

	}

	@Override
	public Integer queryRepCountByStuIdForSelect(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 LeaStudentCourseDao 】-【 queryRepCountByStuIdForSelect 】- 开始运行 ");

		final String query = "SELECT COUNT(*) FROM lea_student_course WHERE stu_id = :stuId AND ness = 0";
		logger.debug(" 数据库执行语句为 " + query);

		Integer count = queryCount(query, map);

		logger.debug(" 【 Dao 】-【 LeaStudentCourseDao 】-【 queryRepCountByStuIdForSelect 】- 完成运行 ");
		return count;

	}

	@Override
	public List<LeaStudentCourseRep> queryRepListByStuId(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 LeaStudentCourseDao 】-【 queryRepListByStuId 】- 开始运行 ");

		final String query = "SELECT g.id, g.course FROM lea_student AS a, lea_bunch AS b, lea_term AS c,"
				+ " edu_major_module AS d, edu_module_course AS e, edu_module AS f, edu_course AS g"
				+ " WHERE a.id = :stuId AND a.bunch_id = b.id AND b.term_id = c.id AND c.major_id = d.major_id"
				+ " AND d.module_id = e.module_id AND e.course_id = g.id AND d.module_id = f.id AND f.ness = 0"
				+ " LIMIT :startPage, :size";
		logger.debug(" 数据库执行语句为 " + query);

		List<LeaStudentCourseRep> array = queryList(query, LeaStudentCourseRep.class, map);

		logger.debug(" 【 Dao 】-【 LeaStudentCourseDao 】-【 queryRepListByStuId 】- 完成运行 ");
		return array;

	}

	@Override
	public List<LeaStudentCourseRep> queryRepListByStuIdForSelect(final Map<String, Object> map)
			throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 LeaStudentCourseDao 】-【 queryRepListByStuIdForSelect 】- 开始运行 ");

		final String query = "SELECT b.id, b.course FROM lea_student_course AS a, edu_course AS b"
				+ " WHERE a.stu_id = :stuId AND a.ness = 0 AND a.course_id = b.id LIMIT :startPage, :size";
		logger.debug(" 数据库执行语句为 " + query);

		List<LeaStudentCourseRep> array = queryList(query, LeaStudentCourseRep.class, map);

		logger.debug(" 【 Dao 】-【 LeaStudentCourseDao 】-【 queryRepListByStuIdForSelect 】- 完成运行 ");
		return array;

	}

}
